#include <AVUITileBrush.h>

namespace AVUI {

class IClientSubgraphCapture;
class Visual;

class VisualBrush : public TileBrush
{
    friend class Application;
    friend class ShaderEffect;
public:

    VisualBrush();
    ~VisualBrush();

    DECLARE_ELEMENT(VisualBrush, TileBrush);

    void set_ActiveBrush(Renderer* pRenderer);

    DECLARE_DEPENDENCY_PROPERTY(Visual);
    TRefCountedPtr<Visual> get_Visual() { return (Visual*)(Object*)GetValue(get_VisualProperty()); }
    void set_Visual(Visual* pValue) { SetValue(get_VisualProperty(), (Object*)pValue); } 

    virtual void RenderDependencies(Renderer* pRenderer);
    virtual bool ContainsRenderDependencies() const { return true; };

    virtual void Precompute() AVUI_OVERRIDE;

protected:

    virtual TRefCountedPtr<Freezable> CreateInstanceCore() AVUI_OVERRIDE { return object_allocate<VisualBrush>().get_Ptr(); }

private:
    IClientSubgraphCapture* get_ClientSubgraphCapture() { return m_pClientSubgraphCapture; }
    static void StaticConstructor();
    bool Enter();
    void Exit();

    void OnRenderFinished();
    void UpdateVisualBrushRootProperties(Visual* pOld, Visual* pNew);

    static void OnVisualChanged(DependencyObject* pDO, DependencyPropertyChangedEventArgs* e);

    IClientSubgraphCapture* m_pClientSubgraphCapture;
    bool m_isSimpleMediaBrush;
    bool m_reentrancyFlag;
};



}; // namespace AVUI
